from django.contrib.auth.models import Group, Permission
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework.viewsets import ModelViewSet

from apps.meiduo_mall_admin.serializers.group import GroupSerializer
from apps.meiduo_mall_admin.serializers.permission import PermissionSerialzier
from apps.meiduo_mall_admin.utils import PageNum


class GroupView(ModelViewSet):
    """获取用户组表列表数据"""

    # 设置序列化器
    serializer_class = GroupSerializer
    # 获取模型类数据
    queryset = Group.objects.all()
    # 分页
    pagination_class = PageNum


class GroupSimpleAPIView(APIView):
    """获取权限表数据"""
    def get(self,request):
        # 获取权限表的所有数据
        pers = Permission.objects.all()
        # 使用序列化器
        serializer = PermissionSerialzier(pers,many=True)
        # 返回响应
        return Response(serializer.data)

